﻿<Page x:Class="SlotDuino.UI.Pages.ChampionshipCreate"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:dal="clr-namespace:SlotDuino.DAL;assembly=SlotDuino.DAL"
      mc:Ignorable="d"
      xmlns:my="clr-namespace:SlotDuino.UI.Controls"
      xmlns:my1="clr-namespace:SlotDuino"
	  Title="ChampionshipCreate" Loaded="Page_Loaded">

    <Page.Resources>
        <CollectionViewSource x:Key="templateViewSource" d:DesignSource="{d:DesignInstance dal:ChampionshipTemplate, CreateList=True }" />
        <CollectionViewSource x:Key="pilotsViewSource" d:DesignSource="{d:DesignInstance dal:Pilot, CreateList=True }" />
        <CollectionViewSource x:Key="enroll" d:DesignSource="{d:DesignInstance dal:ChampionshipEnrollment, CreateList=True}" />
    </Page.Resources>

    <StackPanel>
        <GroupBox Header="Novo campeonato" Margin="0,0,0,5" MinHeight="400" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Page, AncestorLevel=1}, Path=CurrentInstance}">
            <StackPanel>
                <StackPanel Orientation="Horizontal" Margin="5">
                    <Label 	Content="Nome:" x:Name="lblChampionship" Height="15.96" Margin="5" />
                    <TextBox 							 x:Name="txtName" TabIndex="1" Margin="5" Width="593.5" HorizontalAlignment="Center" Text="{Binding Path=Name, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, ValidatesOnDataErrors=True}" MaxLength="50" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" Margin="5" >
                    <Label 	Content="Inicio:" Margin="5" Height="15.96" />
                    <DatePicker Margin="5" Width="110" TabIndex="40" HorizontalAlignment="Left" VerticalAlignment="Center" SelectedDate="{Binding Path=StartDate, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}" Name="dtpStart" LostFocus="dtpStart_LostFocus" />
                    <Label 	Content="Término:" Margin="5" Height="15.96" d:LayoutOverrides="Height" />
                    <DatePicker Margin="5" Width="110" TabIndex="40" HorizontalAlignment="Left" VerticalAlignment="Center" SelectedDate="{Binding Path=EndDate, Mode=TwoWay, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" Name="dtpEnd" SelectedDateChanged="dtpEnd_SelectedDateChanged" LostFocus="dtpEnd_LostFocus" />
                </StackPanel>

                <StackPanel Orientation="Vertical" >
                    <StackPanel Width="748" Orientation="Horizontal" Margin="5" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Page, AncestorLevel=1}, Path=Template}">
                        <Label 	Content="Modelo:" Margin="5,0,0,5" Height="15.96" d:LayoutOverrides="Height" />
                        <ComboBox x:Name="cmbTemplates" ItemsSource="{Binding Source={StaticResource templateViewSource}}" DisplayMemberPath="Name" SelectedValuePath="Id" Margin="10,5" Height="30" Width="400" IsEditable="True" />
                        <Button Content="Editar"    	Height="32" HorizontalAlignment="Left" 	VerticalAlignment="Top" Width="80" d:LayoutOverrides="VerticalAlignment" Margin="10,5,5,5" Name="btnTemplateEdit" Click="btnTemplateEdit_Click" />
                        <Button Content="Salvar"    	Height="32" HorizontalAlignment="Left" 	VerticalAlignment="Top" Width="80" d:LayoutOverrides="VerticalAlignment" Margin="10,5" Name="btnTemplateSave" Click="btnTemplateSave_Click" />
                    </StackPanel>
                    <StackPanel Width="748" Margin="5">
                        <UniformGrid Rows="1">
                            <StackPanel>
                                <Label 	Content="Tomada de Tempo:" Margin="5,0,0,5" Height="15.96" d:LayoutOverrides="Height" VerticalAlignment="Top" HorizontalAlignment="Left" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox TabIndex="1" HorizontalAlignment="Center" Width="119.5" Height="21.96" VerticalAlignment="Top" Margin="5" Text="{Binding Source={StaticResource templateViewSource}, Path=QualifyingTime, StringFormat=m}" Name="txtQualifyingTime" />
                                    <ComboBox Margin="5,5,0,5" TabIndex="1" VerticalAlignment="Top" Width="105" Name="cmbQualifyTime">
                                        <ComboBoxItem Content="minutos" IsSelected="True" />
                                        <ComboBoxItem Content="segundos" IsSelected="False" />
                                    </ComboBox>
                                </StackPanel>
                            </StackPanel>

                            <StackPanel>
                                <Label 	Content="Duração da Bateria:" Margin="5,0,0,5" Height="15.96" d:LayoutOverrides="Height" VerticalAlignment="Top" HorizontalAlignment="Left" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox TabIndex="1" HorizontalAlignment="Center" Width="119.5" Height="21.96" VerticalAlignment="Top" Margin="5" Text="{Binding Source={StaticResource templateViewSource}, Path=RaceTime, StringFormat=m}" Name="txtRaceTime" />
                                    <ComboBox Margin="5,5,0,5" TabIndex="1" VerticalAlignment="Top" Width="105" Name="cmbRace">
                                        <ComboBoxItem Content="minutos" IsSelected="True" />
                                        <ComboBoxItem Content="segundos" IsSelected="False" />
                                    </ComboBox>
                                </StackPanel>
                            </StackPanel>

                            <StackPanel>
                                <Label 	Content="Duração do Intervalo:" Margin="5,0,0,5" Height="15.96" d:LayoutOverrides="Height" VerticalAlignment="Top" HorizontalAlignment="Left" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox TabIndex="1" HorizontalAlignment="Center" Width="119.5" Height="21.96" VerticalAlignment="Top" Margin="5" Text="{Binding Source={StaticResource templateViewSource}, Path=IntervalTime, StringFormat=m}" Name="txtIntervalTime" />
                                    <ComboBox Margin="5,5,0,5" TabIndex="1" VerticalAlignment="Top" Width="105" Name="cmbInterval">
                                        <ComboBoxItem Content="minutos" IsSelected="True" />
                                        <ComboBoxItem Content="segundos" IsSelected="False" />
                                    </ComboBox>
                                </StackPanel>
                            </StackPanel>
                        </UniformGrid>
                    </StackPanel>
                </StackPanel>
                <Rectangle Fill="White" Height="3" />
                <StackPanel Width="748" Margin="5" Orientation="Horizontal" >
                    <Label 	Content="Piloto:" Margin="5,0,0,5" Height="15.96" d:LayoutOverrides="Height" VerticalAlignment="Center" />
                    <ComboBox x:Name="cmbPilots" ItemsSource="{Binding Source={StaticResource pilotsViewSource}}" DisplayMemberPath="Nickname" SelectedValuePath="Id" Margin="10,5" IsEditable="True" Height="30" Width="400" />
                    <Button Content="Novo"    	Height="32" HorizontalAlignment="Right" Width="80" Margin="10,5" Name="btnNewPilot" Click="btnNewPilot_Click" />
                    <Button Content="Adicionar"    	Height="32" HorizontalAlignment="Right" Width="80" Margin="5" Name="btnAddPilot" Click="btnAddPilot_Click" />
                    <Button Content="Remover"    	Height="32" HorizontalAlignment="Right" Width="80" Margin="5" VerticalAlignment="Bottom" Name="btnRemove" Click="btnRemove_Click" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Page, AncestorLevel=1}, Path=CurrentInstance}">
                    <Grid MinHeight="200" Background="Black" Width="748">
                        
                        <DataGrid DataContext="{StaticResource enroll}" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" 
					        x:Name="dataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" CanUserDeleteRows="False" CanUserAddRows="False" 
					        SelectionMode="Single" Background="{StaticResource SelectedBackgroundBrush}" MinHeight="300" Margin="0" Height="100">
                            <DataGrid.Columns>
                                    <DataGridTextColumn x:Name="Nome"       Binding="{Binding Path=Pilot.Name}"     Header="Nome Piloto" IsReadOnly="True" Width="SizeToHeader" />
                                    <DataGridTextColumn x:Name="Apelido"    Binding="{Binding Path=Pilot.Nickname}" Header="Apelido" IsReadOnly="True" Width="SizeToHeader" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </StackPanel>

                <StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal" Height="34">
                    <Button Content="Cancelar" Height="32" Width="100" Margin="0,0,5,0" IsCancel="True" Name="btnCancel" Command="NavigationCommands.BrowseBack" Click="btnCancel_Click" />
                    <Button Content="Salvar" Height="32" Width="100" Margin="0,0,5,0" IsDefault="True" Name="btnSave" Click="btnSave_Click" />
                    <Button Content="Iniciar" Height="32" Width="100" Margin="0,0,5,0" Name="btnStart" />
                </StackPanel>
            </StackPanel>
        </GroupBox>
    </StackPanel>
</Page>
